package com.atguigu.gmall.publisher.controller;


import com.alibaba.fastjson.JSON;
import com.atguigu.gmall.publisher.bean.NameValue;
import com.atguigu.gmall.publisher.bean.OrderDetailResult;
import com.atguigu.gmall.publisher.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class OrderController {

    @Autowired
    OrderService orderService;

    @GetMapping("/statsByItem")
    public String getStatsByItem(@RequestParam("itemName") String itemName,
                           @RequestParam("date") String date ,
                           @RequestParam("t") String type){

        List<NameValue> nameValueList = orderService.getStatsByItem(itemName,date,type);
        return   JSON.toJSONString(nameValueList);

    }

    @GetMapping("detailByItem")
    public String getDetailByItem(@RequestParam("itemName") String itemName,
                                  @RequestParam("date") String date ,
                                  @RequestParam(value = "pageNo",required = false ,defaultValue = "1") Integer pageNo,
                                  @RequestParam(value = "pageSize",required = false ,defaultValue = "20") Integer pageSize){

        OrderDetailResult orderDetailResult=   orderService.getDetailByItem(itemName,date,pageNo,pageSize);
        return  JSON.toJSONString(orderDetailResult);
    }

}
